package com.tfswx.jcyw.ruleenginedesigner.api;

import com.tfswx.jcyw.ruleenginedesigner.bean.ApiResult;
import com.tfswx.jcyw.ruleenginedesigner.dto.yhgl.*;
import com.tfswx.jcyw.ruleenginedesigner.service.YhglService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.NonNull;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/yhgl")
@Api(tags = "用户管理")
public class YhglController {

    @Resource
    private YhglService yhglService;

    @ApiOperation("获取用户列表")
    @PostMapping("/queryYhList")
    public ApiResult<List<YhListQueryOutputDTO>> queryYhList(@NonNull @RequestBody @Validated YhListQueryInputDTO inputDTO) {
        List<YhListQueryOutputDTO> yhList = yhglService.queryYhList(inputDTO);
        return ApiResult.success(yhList);
    }

    @ApiOperation("添加用户")
    @PostMapping("/addYh")
    public ApiResult<String> addYh(@NonNull @RequestBody @Validated YhAddInputDTO inputDTO) {
        String rybm = yhglService.addYh(inputDTO);
        return ApiResult.success(rybm);
    }

    @ApiOperation("修改用户")
    @PostMapping("/updateYh")
    public ApiResult<Boolean> updateYh(@NonNull @RequestBody @Validated YhUpdateInputDTO inputDTO) {
        boolean isSucc = yhglService.updateYh(inputDTO);
        return ApiResult.success(isSucc);
    }

    @ApiOperation("恢复用户")
    @PostMapping("/undeleteYh")
    public ApiResult<Boolean> undeleteYh(@NonNull @RequestBody @Validated YhUndeleteInputDTO inputDTO) {
        boolean isSucc = yhglService.undeleteYh(inputDTO);
        return ApiResult.success(isSucc);
    }

    @ApiOperation("删除用户")
    @PostMapping("/deleteYh")
    public ApiResult<Boolean> deleteYh(@NonNull @RequestBody @Validated YhDeleteInputDTO inputDTO) {
        boolean isSucc = yhglService.deleteYh(inputDTO);
        return ApiResult.success(isSucc);
    }

    @ApiOperation("登录")
    @PostMapping("/dl")
    public ApiResult<DlOutputDTO> dl(@NonNull @RequestBody @Validated DlInputDTO inputDTO) {
        DlOutputDTO dlOutputDTO = yhglService.dl(inputDTO);
        return ApiResult.success(dlOutputDTO);
    }

    // @ApiOperation("设置密码")
    @PostMapping("/setPassword")
    public ApiResult<Boolean> resetPassword(@NonNull @RequestBody @Validated PasswordSetInputDTO inputDTO) {
        boolean isSucc = yhglService.setPassword(inputDTO);
        return ApiResult.success(isSucc);
    }
}
